package cn.xinfei.xdecision.common.model.component.scorecard.vo;

import cn.xinfei.xdecision.common.model.component.IgnoredParamCheck;
import cn.xinfei.xdecision.common.model.component.scorecard.ScorecardDimension;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ScorecardDimensionVo extends ScorecardDimension implements Serializable {

    @IgnoredParamCheck
    private static final long serialVersionUID = 4920595561931964004L;

    private List<ScorecardDetailVo> children;  // 明细

    public void recursionNodeType() {
        if (!CollectionUtils.isEmpty(this.children)) {
            this.children.forEach(this::recursionNodeType);
        }
    }

    public void recursionNodeType(ScorecardDetailVo scorecardDetailVo) {
        List<ScorecardDetailVo> childrenDetails = scorecardDetailVo.getChildren();
        if (CollectionUtils.isEmpty(childrenDetails)) {
            scorecardDetailVo.setNodeType(2);
        } else {
            scorecardDetailVo.setNodeType(1);
            childrenDetails.forEach(this::recursionNodeType);
        }
    }
}
